import tkinter as tk
from tkinter import messagebox

from gui.word_table_line2solid_window import WordTableLine2SolidWindow
from gui.swagger2word_window import Swagger2WordWindow


class MainWindow:
    def __init__(self, master):
        self.swagger2word_window = None
        self.word_table_line2solid = None
        self.container = None
        self.file_menu = None
        self.menu_bar = None
        self.master = master
        self.current_frame = None
        self.create_widgets()

    def create_widgets(self):
        self.menu_bar = tk.Menu(self.master)
        self.file_menu = tk.Menu(self.menu_bar, tearoff=0)
        self.file_menu.add_command(label="swagger转word文档", command=self.show_first_sub_window)
        self.file_menu.add_command(label="word文档表格线条转实线", command=self.show_second_sub_window)
        self.menu_bar.add_cascade(label="菜单", menu=self.file_menu)
        self.master.config(menu=self.menu_bar)

        self.container = tk.Frame(self.master)
        self.container.pack(fill=tk.BOTH, expand=True)

        self.swagger2word_window = Swagger2WordWindow(self.container, self)
        self.word_table_line2solid = WordTableLine2SolidWindow(self.container, self)

        self.show_first_sub_window()

    def show_frame(self, frame):
        if self.current_frame:
            self.current_frame.pack_forget()
        frame.pack(fill=tk.BOTH, expand=True)
        self.current_frame = frame

    def show_first_sub_window(self):
        self.show_frame(self.swagger2word_window)

    def show_second_sub_window(self):
        self.show_frame(self.word_table_line2solid)

    def show_message(self, message):
        messagebox.showinfo("Message", message)